/**
 * @PROJECT 
 * @DATE 2018年7月20日 下午3:13:09
 * @AUTHOR LUYU
 */
package com.kool.evowkf.action.approve;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kool.core.base.IBaseAction;
import com.kool.core.exception.AppException;
import com.kool.evowkf.bean.io.approve.CMQRYAPRTREEXBean;
import com.kool.evowkf.bean.io.approve.CMQRYTREEZBean;
import com.kool.evowkf.service.ApproveService;

/**
 * @DESCRIBE 查询审批流实例
 * @AUTHOR LUYU
 * @DATE 2018年7月20日 下午3:13:09
 *
 */
@Controller
public class QueryApproveTreeAction implements IBaseAction {
	@Autowired
	private ApproveService service;

	/**
	 * @DESCRIBE
	 * @DATE 2018年7月20日 下午3:13:31
	 *
	 * @param sInput
	 * @return
	 * @throws AppException
	 */
	@Override
	@ResponseBody
	@RequestMapping(value = "/comm/wkf/queryApproveTree", method = RequestMethod.POST)
	public JSONObject doAction(@RequestBody String sInput) throws AppException {
		JSONObject pkgIn = JSONObject.parseObject(sInput);
		JSONArray secIn = pkgIn.getJSONArray("CMQRYAPRTREEX");
		String userCid = null;
		if (secIn != null && secIn.size() > 0) {
			JSONObject propIn = secIn.getJSONObject(0);
			CMQRYAPRTREEXBean ioIn = JSON.toJavaObject(propIn, CMQRYAPRTREEXBean.class);
			userCid = ioIn.getUserCid();
		}

		List<CMQRYTREEZBean> list = service.queryApproveEntity(userCid);

		JSONObject pkgOut = new JSONObject();
		JSONArray secOut = new JSONArray();
		for (CMQRYTREEZBean ioOut : list) {
			JSONObject propOut = (JSONObject) JSON.toJSON(ioOut);
			secOut.add(propOut);
		}
		pkgOut.put("CMQRYTREEZ", secOut);
		return pkgOut;
	}

}
